var data = [];
let oLod = $('.logistics-div');

$('.logistics-btn3').click(function () {

    data.push({
        leaveTime: $('#leave-time').val(),
        id1: $('#leave-id').val(),
        hour: $('#leave-hour').val(),
        id2: $('#leave-id2').val(),
        leaveReason: $('#leave-reason').val()
    })

    let v = data[data.length - 1];
    let oT3 = document.querySelector('#tbody3');
    let oT4 = document.querySelector('#tbody4');
    var oTr = document.createElement('tr');
    var oTr2 = document.createElement('tr');
    oTr.innerHTML = `
            <td>${v.leaveTime}</td>
            <td>${v.id1}</td>
            <td>${v.hour}</td>
            <td>${v.id2}</td>
            <td>${v.leaveReason}</td>
            
        `;
    oTr2.innerHTML = `
            <td>${v.leaveTime}</td>
            <td>${v.hour}</td>
            <td>${v.id2}</td>
            <td>${v.leaveReason}</td>
            
        `;
    console.log(oTr)
    oT3.appendChild(oTr);
    oT4.appendChild(oTr2);
    //隐藏模态框
    let oLod1 = $('.modal-backdrop');
    oLod1.css({display: 'none'});
    oLod.css({display: 'none'});

})
$(function () { $('#myModal1').on('hide.bs.modal', function () {

    //清空模态框内容
    $("#leave-time").val('');
    $('#leave-id').val('');
    $('#leave-hour').val('');
    $('#leave-id2').val('');
    $('#leave-reason').val('')
})
});

var logisticsData = [
    {time: '2019 - 5 - 13', all: 75, attendance: 74, absenteeism: 1, reason: 'xx:请假'},
    {time: '2019 - 5 - 12', all: 75, attendance: 75, absenteeism: 0, reason: '无'},
    {time: '2019 - 5 - 11', all: 75, attendance: 75, absenteeism: 0, reason: '无'},
    {time: '2019 - 5 - 10', all: 75, attendance: 73, absenteeism: 2, reason: 'xx:请假,xx：迟到'}
]
let oT1 = document.querySelector('#tbody1');
logisticsData.forEach(function (v, i) {
    let oTr = document.createElement('tr');
    oTr.innerHTML = `
            <td>${v.time}</td>
            <td>${v.all}</td>
            <td>${v.attendance}</td>
            <td>${v.absenteeism}</td>
            <td>${v.reason}</td>
        `;
    /*console.log(oT1)
    console.log(oTr)*/
    oT1.appendChild(oTr);
});

var n=null;
var oneData = [
    {time: '2019 - 5 - 13', amTime:'08:17',pmTime:'17:04', reason: '正常'},
    {time: '2019 - 5 - 12', amTime:'08:55',pmTime:'17:04', reason: '迟到'},
    {time: '2019 - 5 - 11', amTime:'08:55',pmTime:'17:04', reason: '正常'},
    {time: '2019 - 5 - 11', amTime:'08:55',pmTime:'14:04', reason: '迟到，早退'},

]

let oT2 = document.querySelector('#tbody2');
oneData.forEach(function (v, i) {
    let oTr3 = document.createElement('tr');
    oTr3.innerHTML = `
            <td>${v.time}</td>
            <td>${v.amTime}</td>
            <td>${v.pmTime}</td>
            <td>${v.reason}</td>
        `;
    /*console.log(oT1)
    console.log(oTr)*/
    oT2.appendChild(oTr3);
});



//正则
$('#leave-time').blur(function () {
    var reg=/^(?:(?!0000)[0-9]{4}-(?:(?:0[1-9]|1[0-2])-(?:0[1-9]|1[0-9]|2[0-8])|(?:0[13-9]|1[0-2])-(?:29|30)|(?:0[13578]|1[02])-31)|(?:[0-9]{2}(?:0[48]|[2468][048]|[13579][26])|(?:0[48]|[2468][048]|[13579][26])00)-02-29)$/
var str=$('#leave-time').val();
    if (reg.test(str)){
        $('#span2').css({display:'block',color:'green'});
        $('#span1').css({display:'none',color:'red'});
    }else {
        $('#span1').css({display:'block',color:'red'});
        $('#span2').css({display:'none',color:'green'});
    }

});

$('#leave-id').blur(function () {
    var reg=/^[\u4e00-\u9fa5]{0,}$/
    var str=$('#leave-id').val();
    if (reg.test(str)){
        $('#span3').css({display:'none',color:'red'});
        $('#span4').css({display:'block',color:'green'});
    }else {
        $('#span3').css({display:'block',color:'red'});
        $('#span4').css({display:'none',color:'green'});
    }

});

$('#leave-hour').blur(function () {
    var reg=/^[0-9]{1,2}小时$/
    var str=$('#leave-hour').val();
    if (reg.test(str)){
        $('#span5').css({display:'none',color:'red'});
        $('#span6').css({display:'block',color:'green'});
    }else {
        $('#span5').css({display:'block',color:'red'});
        $('#span6').css({display:'none',color:'green'});
    }

});

$('#leave-id2').blur(function () {
    var reg=/^[\u4e00-\u9fa5]{0,}$/
    var str=$('#leave-id2').val();
    if (reg.test(str)){
        $('#span7').css({display:'none',color:'red'});
        $('#span8').css({display:'block',color:'green'});
    }else {
        $('#span7').css({display:'block',color:'red'});
        $('#span8').css({display:'none',color:'green'});
    }
});

$('#leave-reason').blur(function () {
    var reg=/^[\u4e00-\u9fa5]{2,}$/
    var str=$('#leave-reason').val();
    if (reg.test(str)){
        $('#span9').css({display:'none',color:'red'});
        $('#span10').css({display:'block',color:'green'});
    }else {
        $('#span9').css({display:'block',color:'red'});
        $('#span10').css({display:'none',color:'green'});
    }
});
